package org.wordpress.android;

import org.wordpress.android.comments.Comment;
import org.wordpress.android.comments.CommentAdapter;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import static org.wordpress.android.comments.Comment.APPROVED;
import static org.wordpress.android.comments.Comment.REMOVED;
import static org.wordpress.android.comments.Comment.SPAM;

public class CommentClickListener implements OnClickListener {

    private ListView listView;
    private int action;

    public CommentClickListener(ListView view, int action) {
        super();
        this.action = action;
        this.listView = view;
    }

    @Override
    public void onClick(View view) {
        CommentAdapter adapter = (CommentAdapter) this.listView.getAdapter();
        Comment selectedComment = (Comment) this.listView.getSelectedItem();
        selectedComment.setStatus(this.action);
        if (this.action == APPROVED) {
            // TODO Call Wordpress XMLRPC service to approve comment
        } else if (this.action == SPAM) {
            // TODO Call Wordpress XMLRPC service to mark comment as spam
        } else if (this.action == REMOVED) {
            // TODO Call Wordpress XMLRPC service to remove comment
        }
        adapter.getComments().remove(selectedComment);
    }
}
